package com.dev;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.app.Application;
public class CheckableItem extends LinearLayout{
	TextView title;
	public Box box;
	public int borderWidth=3;
	public int borderColor=MainActivity.CYAN;
	int textColor=0xff000000;
	public boolean border=true;
	public CheckableItem(MainActivity ma,String s){
		super(ma);
		title=new TextView(ma);
		title.setText(s);
		title.setTypeface(Typeface.MONOSPACE);
		title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
		title.setTextColor(textColor);
		title.setGravity(Gravity.CENTER_VERTICAL);
		title.setPadding(5, 0, 0, 0);
		setOrientation(HORIZONTAL);
		setWillNotDraw(false);
		addView(title,new LayoutParams(0,-1,1));
		box=new Box(ma);
		addView(box,-2,-1);
	}
	@Override
	public void setEnabled(boolean enabled){
		if(enabled)title.setTextColor(textColor);else title.setTextColor(0x77888888);
		super.setEnabled(enabled);
	}
	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		if(border){
			Paint p=new Paint();
			p.setColor(borderColor);
			canvas.drawRect(0,getHeight() - borderWidth,getWidth(),getHeight(), p);
		}
	}
	public static class Box extends IconView{
		Bitmap b;
		public Box(Context ma){
			super(ma);
			b=BitmapFactory.decodeResource(getResources(),R.drawable.ic_tick);
		}
		public void onDraw(Canvas cvs){
			int width=(int)(getHeight()*0.6);
			Paint p=new Paint();
			p.setColor(0xff777777);
			p.setStyle(Paint.Style.STROKE);
			p.setStrokeWidth(width/10);
			Rect rr=new Rect();
			rr.left=(getWidth()-width)/2;
			rr.top=(getHeight()-width)/2;
			rr.right=rr.left+width;
			rr.bottom=rr.top+width;
			cvs.drawRect(rr,p);
			if(isSelected())
				cvs.drawBitmap(b,new Rect(0,0,b.getWidth(),b.getHeight()),rr,p);
			super.onDraw(cvs);
		}
	}
}
